package com.ts.api.module.api.entity.bo;

import com.gitee.apanlh.util.base.BigDecimalUtils;
import com.gitee.apanlh.util.base.Eq;
import com.ts.api.common.constant.productbill.ProductBillEnum;
import lombok.Data;

import java.math.BigDecimal;
import java.math.RoundingMode;

/**
 */
@Data
public class ApiKeyAmountBO {

    /** 机构id */
    private Long productId;
    /** 机构计划id */
    private Long productPlanId;
    /** 用户id */
    private Long userId;
    /** 渠道id */
    private Long loanChannelId;
    /** 客户端id */
    private String apiClientId;
    /** 手机号md5 */
    private String phoneMd5;
    /** 机构计划价格 */
    private BigDecimal planPrice;
    /** 是否平台计划 */
    private Boolean hasPlatform;
    /** 是否本地库存在 */
    private Boolean hasLocalExist;

    /**
     * 获得【扣款类型】
     *
     * @return
     */
    public ProductBillEnum obtainDeductType() {
        ProductBillEnum result = null;

        boolean hasPlatform = Eq.object(this.getHasPlatform(), Boolean.TRUE);
        if (hasPlatform) {
            result = ProductBillEnum.PLAT_PLAN;
        } else {
            result = ProductBillEnum.PRODUCT_PLAN;
        }
        boolean hasLocalExist = Eq.object(this.getHasLocalExist(), Boolean.TRUE);
        if (hasLocalExist) {
            result = ProductBillEnum.WAKE;
        }

        return result;
    }

    /**
     * 获得【价格】
     *
     * @param share
     * @param price
     * @return
     */
    public BigDecimal obtainPrice(BigDecimal share, BigDecimal price) {
        BigDecimal result = null;

        if (!Eq.str(share.toString(), "0.00")) {
            BigDecimal percent = BigDecimalUtils.division(share, 100);
            result = BigDecimalUtils.multiply(this.getPlanPrice(), percent).setScale(2, RoundingMode.DOWN);
        } else {
            result = price;
        }

        return result;
    }
}
